<script>
	import {
		mapMutations
	} from 'vuex';

	export default {
		onLaunch: function() {
			this.getPlatform();
			this.getNetworkType();
		},
		methods: {
			getPlatform() {
				uni.showLoading({
					title: '获取系统信息...'
				});
				
				const systemInfo = uni.getSystemInfoSync();
				this.updatePlatform(systemInfo.osName ? systemInfo.osName : systemInfo.platform);
				
				// 状态栏高度
				let statusBarHeight = 0;
				// #ifdef APP
				statusBarHeight = plus.navigator.getStatusbarHeight() * plus.screen.scale;
				// #endif
				// #ifdef H5
				statusBarHeight = 44;
				// #endif
				// #ifdef MP-WEIXIN
				statusBarHeight = systemInfo.statusBarHeight;
				// #endif
				this.updateHeight({
					windowHeight: systemInfo.windowHeight,
					statusBarHeight
				});
				
				uni.hideLoading();
			},
			getNetworkType() {
				const that = this;

				uni.getNetworkType({
					success(res) {
						if (res.errMsg === 'getNetworkType:ok') {
							that.updateNetworkType(res.networkType);
						}
					}
				});
				uni.onNetworkStatusChange((res) => {
					that.updateNetworkType(res.networkType);
				});
			},
			...mapMutations('system', ['updatePlatform', 'updateNetworkType', 'updateHeight'])
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	body {
		font-family: 'Arial Negreta', 'Arial Normal', 'Arial', sans-serif;
		font-size: 24rpx;
		color: $uni-text-color;
		background-color: $uni-bg-color;
	}
</style>
